package com.hange.ymcc.service.impl;

import com.hange.ymcc.constant.Regexconstant;
import com.hange.ymcc.service.ITokenService;
import com.hange.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TokenServiceImpl implements ITokenService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;


    @Override
    public String createToken(Long id) {
        /**
         * 1. 生成一个token
         * 2. 存入redis，给一个过期时间
         * 3. 返回token给页面
         */
        String token = StrUtils.getComplexRandomString(16);
        redisTemplate.opsForValue().set(
                Regexconstant.REDIS_KEY_TOKEN_ORDER,
                token,
                10,
                TimeUnit.MINUTES
        );

        return token;
    }
}